package com.itheima.service.impl;

import com.itheima.constant.MessageConstant;
import com.itheima.mapper.OrderMapper;
import com.itheima.pojo.Result;
import com.itheima.service.OrderService;
import com.itheima.utils.DateUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public Result findDetailById(String strId) {
        int id = 0;
        if (strId != null) {
            id = Integer.parseInt(strId);
        }
        System.out.println("查询的id是:"+id);
        Map map = orderMapper.findDetailById(id);

        //转换日期格式，否则页面上的日期会有时分秒
        Date orderDate = (Date) map.get("orderDate");
        try {
            map.put("orderDate", DateUtils.parseDate2String(orderDate));
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(map);

        if (map == null) {
            return new Result(false, MessageConstant.ADD_ORDER_FAIL);
        }else{
            return new Result(true, MessageConstant.HAS_ORDERED,map);
        }
    }
}
